package org.supda.system.controller.monitor;

import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.supda.system.controller.common.BaseController;
import org.supda.system.entity.TRole;
import org.supda.system.entity.TServerWarnProperties;
import org.supda.system.service.RoleService;
import org.supda.system.service.TServerWarnPropertiesService;
import org.supda.system.service.UserService;

/**
 * 配置信息控制器
 * @author supda
 * @Date 2017-2-24 下午3:38:47
 *
 */
@Controller
@RequestMapping("/property")
public class PropertyController  extends BaseController{
	
	@Inject private TServerWarnPropertiesService propertiesService;
	
	@Inject private RoleService roleService;
	
	/**
	 * 告警列表UI
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"/",""}, method=RequestMethod.GET, produces="text/html;charset=utf-8")
	public String warnUI(HttpServletRequest request, Model model){
		
		//得到最新配置信息
		TServerWarnProperties serverWarnProperties = propertiesService.getLastWarnProperties();
		List<TRole> roles = roleService.findAllRole();
		
		model.addAttribute("roles", roles);
		model.addAttribute("serverWarnProperties", serverWarnProperties);
		
		return SYSTEM_MONITOR_VIEW_PACKAGE+"property/property";
	}
	
	@RequestMapping(value = "/edit", method=RequestMethod.POST, produces="text/html;charset=utf-8")
	public @ResponseBody String edit(
			HttpServletRequest request, 
			TServerWarnProperties properties,
			Long id){
		try{
			propertiesService.edit(properties , id);
		}catch(Exception e){
			return RESPONSE_FAIL;
		}
		return RESPONSE_SUCCESS;
	}
	
}
